//
//  YDFooterView.swift
//  weibo
//
//  Created by 孙亚东 on 16/6/27.
//  Copyright © 2016年 Sunyadong. All rights reserved.
//

import UIKit

class YDFooterView: UIView {
    
    var userViewModel: YDUserViewModel? {
        
        didSet{
            
            retweetButton.setTitle(userViewModel?.retweetString, forState: .Normal)
            commentButton.setTitle(userViewModel?.commentString, forState: .Normal)
            goodButton.setTitle(userViewModel?.goodString, forState: .Normal)
            
            
            
        }
        
        
    }


    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    func setupUI () {
    
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(goodButton)
        
        //设置frame
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self).offset(10)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.right.equalTo(commentButton.snp_left)
     
            
        }
        
        
        commentButton.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.width.equalTo(retweetButton)
    
        }
        
        
        goodButton.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.right.equalTo(self).offset(-10)
            make.left.equalTo(commentButton.snp_right)
            make.width.equalTo(commentButton)
        
        }
  
    }
    
    //懒加载
    // 第三步: 懒加载控件
    
    /// 转发按钮
    private lazy var retweetButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return button
    }()
    
    /// 评论按钮
    private lazy var commentButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return button
    }()
    
    ///  点赞
    private lazy var goodButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("点赞", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_unlike"), forState: UIControlState.Normal)

//        button.tag = 1
        
         button.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Selected)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        button.addTarget(self, action: "btnClick:", forControlEvents: .TouchUpInside)
        
        return button
    }()
    
    
    func btnClick (goodBtn: UIButton) {
    
//        if goodBtn.tag % 2 == 0 {
//        
//        goodBtn.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
//            
            goodBtn.selected = !goodBtn.selected
        //
//        }else {
//        
//        goodBtn.setImage(UIImage(named: "timeline_icon_unlike"), forState: UIControlState.Normal)
//            
//        
//        }
//        
//        goodBtn.tag  =  goodBtn.tag + 1
        
        
        
        

        }


}
